#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

# Change name of configfile to your needs
. /etc/conf.d/cpwsgid

if [ -f "$cpwsgid_pidfile" ]; then
    PID=$(cat $cpwsgid_pidfile)
else
    PID=""
fi

case "$1" in
    start)
        stat_busy "Starting $cpwsgid"
        [ -z "$PID" ] && "$cpwsgid $cpwsgid_args" &>/dev/null
        if [ $? = 0 ]; then
            add_daemon $cpwsgid
            stat_done
        else
            stat_fail
            exit 1
        fi
        ;;
    stop)
        stat_busy "Stopping $cpwsgid"
        [ -n "$PID" ] && kill $PID &>/dev/null
        if [ $? = 0 ]; then
            rm_daemon $cpwsgid
            stat_done
        else
            stat_fail
            exit 1
        fi
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
esac

